package rss_POJO;

import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author RS-team
 */
@Entity
@Table(name = "MUSICGENRE")
//@Table(name = "MUSICGENRE", uniqueConstraints = {
//    @UniqueConstraint(columnNames = {"NAME"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicGenre.findAll", query = "SELECT m FROM MusicGenre m"),
    @NamedQuery(name = "MusicGenre.findByMusicgenreid", query = "SELECT m FROM MusicGenre m WHERE m.musicgenreid = :musicgenreid"),
    @NamedQuery(name = "MusicGenre.findByName", query = "SELECT m FROM MusicGenre m WHERE m.name = :name")})
public class MusicGenre implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "MUSICGENREID")  // είναι not nullable αλλά και unique ως primary key
        @Basic(optional = false)
        private Integer musicgenreid;
    @Column(name = "NAME", nullable = false, unique = true, length = 100)  // μοναδικότητα κύριου αναγνωριστικού πεδίου αναζήτησης
        @Basic(optional = false)
        private String name;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "musicgenreId")
        private Collection<Artist> artistCollection;

    /* default constructor */
    public MusicGenre() {
    }
    /* και ο πλήρης constructor */
    public MusicGenre(String name) {
        this.musicgenreid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.name = name;
    }

    /* getters */
    public Integer getMusicgenreid() { return musicgenreid; }
    public String getName() { return name; }

    /* setters εκτός από το primary key */
    //public void setMusicgenreid(Integer musicgenreid) { this.musicgenreid = musicgenreid; }
    public void setName(String name) { this.name = name; }

    @XmlTransient
    /* getter και setter για την artistCollection */
    public Collection<Artist> getArtistCollection() {
        return artistCollection;
    }
    public void setArtistCollection(Collection<Artist> artistCollection) {
        this.artistCollection = artistCollection;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (musicgenreid != null ? musicgenreid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicGenre)) {
            return false;
        }
        MusicGenre other = (MusicGenre) object;
        if ((this.musicgenreid == null && other.musicgenreid != null) || (this.musicgenreid != null && !this.musicgenreid.equals(other.musicgenreid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rss_POJO.MusicGenre[ musicgenreid=" + musicgenreid + " ]";
    }

}